package project.layer.physical;

//import java.util.ArrayList;
//import java.util.HashMap;



import project.data.DataHolder;

import project.data.FeasibilityDataStack;
import project.events.roadEvents.CrossRoadsCreatedEvent;
import project.layer.ant.AntTickListener;

import framework.events.EventBroker;
import framework.layer.physical.connections.Connector;
import framework.layer.physical.position.ConnectorPosition;

public class Crossroad extends Connector<Truck, Crossroad, Road> implements AntTickListener{

	public static final int CAPACITY = Integer.MAX_VALUE;
	private PickUpPoint pickUpPoint;
	private DropOffPoint dropOffPoint;
	private final DataHolder dataHolder;


	public Crossroad() {
		super(CAPACITY, CAPACITY);
		this.dataHolder = new DataHolder();
//		this.packageAntPheromoneStacks = new HashMap<Road, PheromoneStack>();
		EventBroker.getEventBroker().notifyAll(new CrossRoadsCreatedEvent(this));
	}
	

	@Override
	protected boolean canEnterOffroad() {
		return false;
	}

	@Override
	protected boolean canEnterOnroad() {
		return true;
	}

	@Override
	protected boolean canLeaveOffroad() {
		return false;
	}

	@Override
	protected boolean canLeaveOnroad() {
		return true;
	}

	@Override
	protected void executeSpecificDeploymentOptions(Truck connectionEntity,
			ConnectorPosition<Truck, Crossroad, Road> pos) {
	}

	@Override
	protected void onEnterOffroad(Truck connectionEntity, Road fromConnection) {
	}

	@Override
	protected void onEnterOnroad(Truck connectionEntity, Road fromConnection) {
	}

	@Override
	protected void onLeaveOffroad(Truck connectionEntity, Road toConnection) {
	}

	@Override
	protected void onLeaveOnroad(Truck connectionEntity, Road toConnection) {
	}

	@Override
	public void processAntTick() {
		// TODO Auto-generated method stub
		
	}
	public boolean hasPickUpPoint(){
		return pickUpPoint != null;
	}
	public boolean hasDropOffPoint(){
		return dropOffPoint != null;
	}
	public DropOffPoint getDropOffPoint(){
		return dropOffPoint;
	}
	public PickUpPoint getPickUpPoint(){
		return pickUpPoint;
	}

	public DataHolder getDataHolder() {
		return dataHolder;
	}

	public void setPickUpPoint(PickUpPoint pickUpPoint) {
		this.pickUpPoint = pickUpPoint;
	}

	public void setDropOffPoint(DropOffPoint dropOffPoint) {
		this.dropOffPoint = dropOffPoint;
	}
	/**
	 * Calculates the euclidean distance based on the latitude/longitude coordinates
	 * 
	 * @param end
	 * @return
	 */
	public long distanceTo(Crossroad end) {
		return getPosition().getDistanceTo(end.getPosition());
	}


	@Override
	protected void outgoingConnectionAdded(Road road) {
		
		getDataHolder().getFeasibilityDataContainer().put(road, new FeasibilityDataStack());
	}

}


